package Tools;

import InterMessages.SunspotsDeployStatus;

import javax.swing.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.concurrent.BlockingQueue;

class StreamGobblerGUI extends Thread {

    protected InputStream is;
    protected String type;
    protected String result;
    protected BlockingQueue queue;


    StreamGobblerGUI(InputStream is, String type, BlockingQueue queue) {
        this.is = is;
        this.type = type;
        synchronized(queue) {
          this.queue = queue;
        }

    }

    public String getResult() {
         synchronized (this){
           return this.result;
        }
        
    }


    public void run() {
        StringBuffer buffer = new StringBuffer();
        try {
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line = null;
            while ((line = br.readLine()) != null) {
                buffer.append(line + "\n");
                queue.put(line+"\n");
                System.out.println(line);
            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
        catch (InterruptedException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        finally {
            result = buffer.toString();
        }

    }
}


